<script>
	import COMM from "@/common/common.js";
	import API from "@/common/api.js";
	import {mapState,mapGetters,mapMutation,mapActions} from "vuex";
	
	export default {
		computed:{
			...mapState({
				pushId:state=>state.push.pushId,
				imei:state=>state.push.imei,
			})
		},
		globalData:{
			TIM_SDK_READY:false,
		},
		methods:{
			
		},
		onLaunch: function() {
			console.log('App Launch')
			this.$store.dispatch("apiGetInit");
			COMM.listenerNet();
			COMM.netChange();
			this.$store.dispatch("getNowAppInfo");
			// #ifdef APP-PLUS
			this.$store.dispatch("getPushId");
			this.$store.dispatch("listenPush");
			this.$store.dispatch("listenPushTap");
			// #endif
			
			this.$store.dispatch("loginByToken").then(res=>{
				if(res.data.data.admin==1){		//商户
					this.$store.dispatch("getSettledByUid",res.data.data.userId).then(settledRes=>{
						if(settledRes.data.data.status==0){		//未提交审核
							// uni.redirectTo({
							// 	url:'/pages/addSettled/addSettled'
							// })
							uni.redirectTo({
								url:'/pages/selectShop/selectShop'
							})
						}else{		//审核通过
							uni.redirectTo({
								url:'/pages/selectShop/selectShop'
							})
						}
					})
				}else{			//非商户
					// this.$store.commit("select",res.data.data.store)
					uni.redirectTo({
						url:'/pages/selectShop/selectShop'
					})
				}
				// 登录成功后同步pushId
				// #ifdef APP-PLUS
				setTimeout(()=>{
					if(this.pushId){
						this.$store.dispatch("editUserInfo",{
							userId:res.data.data.userId,
							pushId:this.pushId,
							imei:this.imei
						})
					}
				},3000)
				// #endif
			}).catch(()=>{
				uni.redirectTo({
					url:'/pages/login/login'
				})
			})
			// #ifdef APP-PLUS
			this.listenPush();
			// APP启动5秒后获取更新信息
			setTimeout(()=>{
				this.$store.dispatch("apiGetUpdateInfo").then(res=>{
					this.$store.dispatch("checkUpDate");
				})
			},3000)
			// #endif
		},
		onShow: function() {
			
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
	
</script>

<style lang="less">
	@import url('iconfont/iconfont.css');
	/*每个页面公共css */
	view {
		box-sizing: border-box;
	}

	.hasTop {
		position: relative;
		top: 90upx;
		padding-top: var(--status-bar-height);
	}

	.garyBg {
		background-color: #f6f6f6;
	}

	.mainCnt {
		padding: 0 28upx;
	}

	// .topZhanWei {
	// 	height: 90upx;
	// 	padding-top: var(--status-bar-height);
	// 	box-sizing: content-box;
	// }

	.tapOpt {
		transition: all 0.1s;
	}

	.tapBg {
		transition: all 0.1s;
	}

	.tapOpt:active {
		opacity: 0.5;
	}

	.tapBg:active {
		background-color: rgba(0, 0, 0, 0.1);
	}

	.serversBtn {
		position: absolute;
		left: 0;
		bottom: 0;
		width: 100%;
		height: 105upx;
		box-shadow: 0rpx -2rpx 21rpx 0rpx rgba(0, 0, 0, 0.05);
		background-color: #FFFFFF;
		border: none;
		z-index: 9999;
		display: flex;
		justify-content: center;
		align-items: center;
		border-radius: 0;

		.iconfont {
			font-size: 52upx;
			color: #ffb423;
			margin-right: 15upx;
		}

		.btnText {
			font-size: 32rpx;
			color: #202932;
		}
	}

	.serversBtn:after {
		border: none;
	}

	.regionBox {
		display: flex;
		flex-direction: column;
		padding: 0 32upx;
		background-color: #FFFFFF;
		box-shadow: 0rpx 3rpx 17rpx 0rpx rgba(201, 202, 208, 0.2);
		border-radius: 10upx;
		margin: 0 17upx;
		margin-bottom: 15upx;
		padding-bottom: 20upx;
		.regionTitle{
			padding: 20upx 0;
			font-size: 36rpx;
				font-weight: bold;
				color: #202932;
		}
	}
	.emptyBox{
		display: flex;
		flex-direction: column;
		align-items: center;
		padding-top: 110upx;
		image{
			width: 220upx;
			height: 220upx;
			margin-bottom: 40upx;
		}
		text{
			font-size: 28upx;
			color: #c3c9d6;
		}
	}
	.required{
		font-size: 28upx;
		color: #FF0000;
	}
	.norequired{
		font-size: 28upx;
		color: rgba(0,0,0,0);
	}
</style>
